Exercise: Harmonographs

In this exercise, you will solve tasks related to harmonographs.

Task 1#

As discussed in the previous lesson, below is the equation for a damped pendulum:

x(t)=Asin(2Ï€ft+p)edtx(t) =Asin(2\pi ft+p)e^{dt}

Problem Statement#

Write a Python function named pendulum() to implement the equation given above. Use the following default values for the parameters:

  • A=1A=1
  • f=100f=100
  • p=0p=0
  • d=0.05d=0.05

Use the following arguments to plot the output of the function against tt:

  • A=1A=1
  • f=2f=2
  • p=0p=0
  • d=0.5d=0.5

Set the range of tt to be the following:

0≤t<2π0\leq t<2\pi

Use all the suitable packages that you have learned throughout the course.

Task 2#

Now we will implement the harmonograph along the x and y axes and plot the output.

Problem Statement#

Use the function defined above to plot a harmonograph along the xx and yy direction. Implement the following equations:

x(t)=2sin(8πt−1)e−0.05t+sin(4πt−π2)e−0.01tx(t)=2sin(8\pi t -1)e^{-0.05t}+sin(4\pi t -\frac{\pi}{2})e^{-0.01t}

y(t)=2sin(4πt−π3)e−0.02t+2sin(4πt−π)e−0.25ty(t)=2sin(4\pi t -\frac{\pi}{3})e^{-0.02t}+ 2sin(4\pi t - \pi)e^{-0.25t}

Set the range of tt to be 0≤t<20π0\leq t<20\pi with 40,00040,000 values in it.

Plot the output of y(t)y(t) against x(t)x(t).

Set the range of tt to be 0≤t<20π0\leq t<20\pi with 40,00040,000 values in it.

Change the values of the function arguments to see how the output changes. You will be amazed by these geometric patterns.

Use all the suitable packages that you have learned throughout the course.

Task 3#

If you have reached this part of the exercise, you must be wondering what possible patterns you can plot by supplying varying arguments to the function. In this task, you will be completely randomizing the output of the harmonograph.

Problem Statement#

Using the function above, implement the following random behavior in your code:

For both xx and yy pendulums, generate:

  • A random number of pendulums in the range: 1≤n<51 \leq n < 5.

  • Random frequencies in the range: 1≤f<401 \leq f < 40.

  • Random amplitudes in the range: 1≤A<51 \leq A < 5.

  • Random phases in the range: 0≤p<Ï€0 \leq p < \pi.

  • Random decay factors in the range: 0≤d<0.10 \leq d < 0.1.

Plot the randomly generated y(t)y(t) against x(t)x(t). Use the following randomization when plotting the data:

  • Break the data set into ss equal parts, where ss can take any random integer value in the range 1≤s<41 \leq s < 4.
  • Plot each slice of data with a different color, which will also be randomly generated.

Make sure to add labels to your plots.

Use all the suitable packages that you have learned throughout the course.

After you complete this task, run the code to see how the output changes with each execution.


The solution to this exercise will be discussed in the next lesson.

Preview: Harmonographs

Solution Review: Harmonographs